<include file="public/header" title="申请提现" body=""/>
<include file="public/header_nav" title="申请提现" href="javascript:history.back(-1)"/>
<style>
	.loginsingup-input .content30 .lsu input {
	    width: 10.556rem;
	}
	.mytit_flash ul li{
		width: 50%;
	}
	.mytit_flash ul .red a{
		color: #f23030;
	}
	.weiprice{
		display: none;
	}
	.pricespan{
		width: 3rem;
	    display: block;
	    float: left;
	    line-height: 1.8rem;
	}
	.prompt{
		position: relative;
		color: #f23030;
		font-size: .6rem;
		line-height: 1.2rem;
	}
</style>
<input type="hidden" id="openid" value="{$user.openid}">

<div class="tit-flash-sale p mytit_flash">
    <div class="maleri30">
        <ul class="">
            <li class="red" onclick="payment(this,1)">
                <a href="javascript:void(0)" class="tab_head">提现到银行卡</a>
            </li>
            <li  onclick="payment(this,2)">
                <a href="javascript:void(0)" class="tab_head">提现到微信</a>
            </li>
       
        </ul>
    </div>
</div>


		<!--提现到银行卡-->
		<div class="loginsingup-input ma-to-20 cardprice">
			<form method="post" id="returnform">
				<div class="content30">
					<!--<div class="lsu" style="height:1.83467rem"><span>账号类型：</span>-->
                          <!--<input type="radio" name="atype" style="width:.8rem;height:1rem;" checked value="支付宝">支付宝-->
                          <!--<input type="radio" name="atype" style="width:.8rem;height:1rem;" value="微信">微信-->
                          <!--<input type="radio" name="atype" style="width:.8rem;height:1rem;" value="银行卡">银行卡-->
					<!--</div>-->
                    <div class="lsu">
                        <span class="pricespan">提现金额：</span>
                        <input type="text" name="money" id="money" value="" usermoney="{$user.user_money}" placeholder="可提现金额：{$user.user_money}元" onKeyUp="this.value=this.value.replace(/[^\d.]/g,'')">
                    </div>
                    <div class="lsu">
                        <span class="pricespan">银行名称：</span>
                        <input type="text" name="bank_name" id="bank_name" value="" placeholder="如：工商银行，支付宝，微信">
                    </div>
					<div class="lsu">
						<span class="pricespan">收款账号：</span>
                        <!-- <input type="text" name="account_bank" id="account_bank"  placeholder="收款账号"/> -->
						<input type="text" name="account_bank" id="account_bank" maxlength="22" placeholder="收款账号" onKeyUp="this.value=this.value.replace(/[^\d]/g,'')">
					</div>
					<div class="lsu">
						<span class="pricespan">开户名：</span>
						<input type="text" name="realname" id="realname" value=""  placeholder="持卡人姓名">
					</div>
                    <div class="lsu">
                        <span class="pricespan">身份证号：</span>
                        <!-- <input type="text" name="idcard" id="idcard" value=""  placeholder="持卡人身份证号"> -->
                        <input type="text" name="idcard" id="idcard" placeholder="持卡人身份证号" onBlur="checkszf(this);"/>
                    </div>
                    <!-- <div class="lsu">
                        <span>支付密码：</span>
                        <input type="password" name="paypwd" id="paypwd" placeholder="支付密码">
                    </div> -->
                    <div class="lsu test">
                        <span class="pricespan">验证码：</span>
                        <input type="text" name="verify_code" id="verify_code" value="" placeholder="请输入验证码" style="width: 7rem;">
                        <img  id="verify_code_img1" src="{:U('User/verify',array('type'=>'withdrawals'))}" onClick="verify(1)" style=""/>
                    </div>
					<div class="lsu submit">
                        <input type="hidden" name="__token__" value="{$Request.token}" />
                        <input type="hidden" name="pay_type" value="1">
						<input type="button" onclick="checkSubmit1()" value="提交申请">
					</div>
				</div>
			</form>
		</div>
		<!--提现到银行卡end-->
		
		<!--提现到微信-->
		<div class="loginsingup-input ma-to-20 weiprice">
			<div class="content30">
				  <div class="lsu">
	                    <span class="pricespan">提现金额：</span>
	                    <input type="text" name="money2" id="money2" value="" usermoney="{$user.user_money}" placeholder="可提现金额：{$user.user_money}元" onKeyUp="this.value=this.value.replace(/[^\d.]/g,'')">
	              </div>
	              
	               <div class="lsu test">
                        <span class="pricespan">验证码：</span>
                        <input type="text" name="verify_code2" id="verify_code2" value="" placeholder="请输入验证码" style="width: 7rem;">
                        <img  id="verify_code_img2" src="{:U('User/verify',array('type'=>'withdrawals'))}" onClick="verify(2)" style=""/>
                    </div>
	              
	              <div class="lsu">
	               		<p class="prompt">注意:提现到微信账户,提现金额必须为整数,微信账户需要实名认证,否则无法提现到微信账户.</p>
	              </div>
	              
	              <div class="lsu submit">
                        <input type="hidden" name="__token__" value="{$Request.token}" />
                        <input type="hidden" id="pay_type" value="2">
						<input type="button" onclick="checkSubmit2()" value="提交申请">
					</div>
             </div>
		</div>
		
		<!--提现到微信end-->
		
		
<script type="text/javascript" charset="utf-8">

	/*支付方式切换*/
	function payment(e,type){
		if(type==1){
			$(e).addClass("red").siblings().removeClass("red");
			$(".weiprice").hide();
			$('.cardprice').show();
		}else if(type==2){
			$(e).addClass("red").siblings().removeClass("red");
			
			$(".weiprice").show();
			$('.cardprice').hide();
		}
	}
	/*支付方式切换end*/


    // 验证码切换
    function verify(type){
        $('#verify_code_img' + type).attr('src','/index.php?m=Mobile&c=User&a=verify&type=withdrawals&r='+Math.random());
    }

    /**
     * 提现到银行卡
     * */
    function checkSubmit1(){
        var bank_name = $.trim($('#bank_name').val());
        var account_bank = $.trim($('#account_bank').val());
        var realname = $.trim($('#realname').val());
        var idcard = $.trim($('#idcard').val());
        var money = parseFloat($.trim($('#money').val()));
        var usermoney = parseFloat({$user_money});  //用户余额
        var verify_code = $.trim($('#verify_code').val());
        //var paypwd= $.trim($('#paypwd').val());
        //验证码
        
        if(bank_name == '' || account_bank == '' || realname=='' || money === '' || idcard === ''){
            showErrorMsg("所有信息为必填")
            return false;
        }
        if(money > usermoney){
            showErrorMsg("提现金额大于您的账户余额")
            return false;
        }
        if(idcard == ''){
            showErrorMsg("持卡人身份证号信息为必填")
            return false;
        }
        if(verify_code == '' ){
            showErrorMsg('验证码不能空')
            return false;
        }
        $.ajax({
            type: "post",
            url :"{:U('Mobile/User/withdrawals')}",
            dataType:'json',
            data:$('#returnform').serialize(),
            success: function(data)
            {
                showErrorMsg(data.msg);
                if(data.status == 1){
                    window.location.href=data.url;
                } else {
//                    window.location.reload();
                    verify(1);
                }
            }
        });
    }

    function checkSubmit2() {
        var money = $.trim($('#money2').val());
        var usermoney = parseFloat({$user_money});  //用户余额
        var verify_code = $.trim($('#verify_code2').val());
        var pay_type = $.trim($('#pay_type').val());

        if(money === ''){
            showErrorMsg("请输入提现金额")
            return false;
        }
        if(parseFloat(money) > usermoney){
            showErrorMsg("提现金额大于您的账户余额")
            return false;
        }
        if (!/^\d+$/.test(money)) {
            showErrorMsg("提现到微信,金额只能为整数")
            return false;
        }
        if(verify_code == '' ){
            showErrorMsg('验证码不能空')
            return false;
        }
        $.ajax({
            type: "post",
            url :"{:U('Mobile/User/withdrawals')}",
            dataType:'json',
            data:{money:money,verify_code:verify_code,pay_type:pay_type},
            success: function(data)
            {
                showErrorMsg(data.msg);
                if(data.status == 1){
                    window.location.href=data.url;
                } else {
//                    window.location.reload();
                    verify(2);
                }
            }
        });
    }
    function checkszf(e){
        var reg=/^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/;
        if(!reg.test($(e).val())){
            alert('身份证号格式错误');
            $(e).val('');
        }
    }

    // $(function(){
    // 	$('input[name="atype"]').click(function(){
    // 		var bankstr = $(this).val();
    // 		if(bankstr =='微信'){
    // 			if($('#openid').val() == ''){
    // 				alert('请在用户中心账号绑定里先扫码绑定微信账号');
    // 				return false;
    // 			}
    // 		}
    // 		if(bankstr != '银行卡'){
    // 			$('#bank_name').val(bankstr);
    // 			$('#bank_name').attr('readonly','readonly');
    // 			if(bankstr == '微信'){
    // 				$('#account_bank').val($('#openid').val());
    // 				$('#account_bank').attr('readonly','readonly');
    // 			}else{
    // 				$('#account_bank').val('');
    // 				$('#account_bank').removeAttr('readonly');
    // 			}
    // 		}else{
    // 			$('#bank_name').val('');
    // 			$('#bank_name').removeAttr('readonly');
    // 		}
    // 	})
    // });
    /**
     * 提示弹窗
     * @param msg
     */
    function showErrorMsg(msg){
        layer.open({content:msg,time:3});
    }
</script>
	</body>
</html>